package control;

import managment.ArraySource;
import managment.ArraySource.MyException;
import managment.InType;
import managment.Manager;
import managment.Prop;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import view.View;

/**
 * @author  Owner
 */
public class SourceControl implements SelectionListener {

	private InType src;
	ArraySource arraySource;
	View view;
	
	private Prop autoType;

	public SourceControl(InType src, Prop autoType) {
		this.src = src;
		this.autoType = autoType;
		view = View.getInstance();
	}

	public void widgetDefaultSelected(SelectionEvent e) {
	}

	public void widgetSelected(SelectionEvent e) {
	    try{
		if (this.src == InType.file) {
		    arraySource = ArraySource.getSuitableInstance(InType.file, 0, view.getDirPath());
		} else {
		    arraySource = ArraySource.getSuitableInstance(InType.auto, view.getAutoArraySize() , autoType);
		}
		Manager.getInstance().addToList(this.arraySource.createTarget());
	    }
	    catch (MyException e1) {
		e1.handle();
	    }
	    
	}
}
